<template>
  <div>
    <el-form :inline="true" :model="dataForm">
      <el-form-item>
        <el-input v-model="dataForm.appName" placeholder="应用名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getAppList()">查询</el-button>
        <el-button type="primary" @click="addInfoHandle()">新增</el-button>
      </el-form-item>
    </el-form>

    <el-table
      :data="tableData"
      row-key="applicationList"
      border size="mini"
      height="350px"
      style="width: 100%;">
      <el-table-column fixed="left" prop="appName" label="应用名称" min-width="150">
      </el-table-column>

      <el-table-column fixed="left" prop="dbName" label="应用简称（英文）" min-width="100">
      </el-table-column>
      <el-table-column fixed="left" prop="appPath" label="应用路径" min-width="200">
      </el-table-column>

      <el-table-column prop="appStatus" align="center" label="状态">
        <template slot-scope="scope">
          <span v-if="scope.row.appStatus == 0">正常</span>
          <span v-else-if="scope.row.appStatus == 1">失效</span>
        </template>
      </el-table-column>

    </el-table>
    <!-- 分页信息 -->
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="total"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!--弹窗-->
    <addInfo v-if="addVisible" ref="addInfo" @refreshDataList="getAppList"></addInfo>

  </div>
</template>

<script>
    import AddInfo from './add-update-info'

    export default {
      name: 'appBase',
      data () {
        return {
          tableData: [],
          dataForm: {
            appName: ''
          },
          addVisible: false,
          pageIndex: 1,
          pageSize: 10,
          totalPage: 0,
          total: 0
        }
      },
      components: {
        AddInfo
      },
      activated () {
        this.init()
      },
      methods: {
        init () {
          this.$nextTick(() => {
            this.getAppList()
          })
        },
        getAppList () {
          this.tableData = []
          this.$http({
            url: this.$http.adornUrl('/app/appBaseList'),
            method: 'post',
            params: this.$http.adornParams({
              'pageNumber': this.pageIndex,
              'pageSize': this.pageSize
            })
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.tableData = data.data.data
              this.totalPage = data.data.pages
              this.total = data.data.total
            } else {
              this.tableData = []
              this.totalPage = 0
            }
            this.dataListLoading = false
          })
        },
        // 每页数
        sizeChangeHandle (val) {
          this.pageSize = val
          this.pageIndex = 1
          this.getStudyCardList()
        },
        // 当前页
        currentChangeHandle (val) {
          this.pageIndex = val
          this.getStudyCardList()
        },
        addInfoHandle (id) {
          this.addVisible = true
          this.$nextTick(() => {
            this.$refs.addInfo.init(id)
          })
        }
      }
    }
</script>

<style scoped>

</style>
